<?php

namespace App\Remote\AMap;

use App\Http\Middleware\OpenShop\WangGuiCityByPower;
use Closure;
use Symfony\Component\HttpFoundation\Response as ResponseAlias;

class Remote extends \App\Remote\Remote
{
    static function getBaseUri(): string
    {
        // TODO: Implement getBaseUri() method.
        return "https://restapi.amap.com";
    }

    /**
     * @return Closure
     */
    public static function registerResponseHandle(): Closure
    {
        return function (int $responseHttpCode, string $responseOriginalContents) {
            if ($responseHttpCode == ResponseAlias::HTTP_OK && isJson($responseOriginalContents)) {
                $responseArr = jsonToArr($responseOriginalContents);
                if ($responseArr["status"] == 1) {
                    return $responseArr;
                }
                throw new \Exception(attributeGet($responseArr, "info", null));
            }
            throw new \Exception($responseOriginalContents);
        }; // TODO: Change the autogenerated stub
    }

    /**
     * @return string
     */
    static function getKey(): string
    {
        // 系统配置里面的key-webServeApiKey
        return WangGuiCityByPower::getRandomAmapKey();
    }
}
